<?php

/**
 * This is the model class for table "usuario".
 *
 * The followings are the available columns in table 'usuario':
 * @property string $nombre_usuario
 * @property string $id_ciudad
 * @property string $nombres
 * @property string $apellidos
 * @property string $contraseÃ±a
 * @property string $numero_telefono
 * @property string $numero_celular
 * @property string $email
 */
class Usuario extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'usuario';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('nombre_usuario, id_ciudad, nombres, apellidos, 
                            contraseña, email', 'required', 'message' =>
                'Debe ingresar : {attribute}'),
            array('nombre_usuario', 'length', 'max' => 20),
            array('nombre_usuario', 'unique', 'attributeName' =>
                'nombre_usuario', 'className' => 'usuario', 'allowEmpty' =>
                false, 'message' => '{attribute} en uso'),
            array('id_ciudad', 'length', 'max' => 3),
            array('nombres, apellidos, email', 'length', 'max' => 50),
            array('contraseña', 'length', 'max' => 15),
            array('numero_telefono', 'numerical', 'integerOnly' => true,
                'max' => 7999999, 'min' => (7000000)),
            array('numero_celular', 'numerical', 'integerOnly' => true,
                'max' => 399999999, 'min' => (30000000)),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('nombre_usuario, id_ciudad, nombres, apellidos, 
                            contraseña, numero_telefono, numero_celular, email',
                'safe', 'on' => 'search'),
        );
    }

    /**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    'ciudad'=>array(self::BELONGS_TO,'Ciudad','id_ciudad'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'nombre_usuario' => 'Nombre Usuario',
			'id_ciudad' => 'Id Ciudad',
			'nombres' => 'Nombres',
			'apellidos' => 'Apellidos',
			'contraseña' => 'Contraseña',
			'numero_telefono' => 'Numero Telefono',
			'numero_celular' => 'Numero Celular',
			'email' => 'Email',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('nombre_usuario',$this->nombre_usuario,true);
		$criteria->compare('id_ciudad',$this->id_ciudad,true);
		$criteria->compare('nombres',$this->nombres,true);
		$criteria->compare('apellidos',$this->apellidos,true);
		$criteria->compare('contraseña',$this->contraseña,true);
		$criteria->compare('numero_telefono',$this->numero_telefono,true);
		$criteria->compare('numero_celular',$this->numero_celular,true);
		$criteria->compare('email',$this->email,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Usuario the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}









